# -*- coding: utf-8 -*-


import execjs
import requests

with open("05-五矿-标准库.js", encoding='utf-8') as f1:
    js_code = f1.read()

ctll = execjs.compile(js_code)

#

'''
1、https://ec.minmetals.com.cn/open/homepage/public  获取key

2、https://ec.minmetals.com.cn/open/homepage/zbs/by-lx-page 带参数返回信息

'''

def index():
    headers = {
        "Accept": "application/json, text/plain, */*",
        "Accept-Language": "en-GB,en;q=0.9,zh-CN;q=0.8,zh;q=0.7",
        "Cache-Control": "no-cache",
        "Origin": "https://ec.minmetals.com.cn",
        "Pragma": "no-cache",
        "Sec-Fetch-Dest": "empty",
        "Sec-Fetch-Mode": "cors",
        "Sec-Fetch-Site": "same-origin",
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36",
        "sec-ch-ua-mobile": "?0",
    }
    res = requests.post("https://ec.minmetals.com.cn/open/homepage/public",headers=headers)
    # print(res.text)
    # print(res.cookies)
    key = res.text
    cookie = res.cookies.get("__jsluid_s")
    params = {
        "inviteMethod": "",
        "businessClassfication": "",
        "mc": "",
        "lx": "ZGYS",
        "dwmc": "",
        "pageIndex": 1
    }
    params_enc = ctll.call("get_data",key,params)
    print(params_enc)
    data = {
        "param":params_enc
    }
    cookies = {
        "SUNWAY-ESCM-COOKIE": "49ffcb95-e67f-40a9-9665-73a70760dd17",
        "__jsluid_s":cookie
    }

    headers = {
        "Accept": "application/json, text/plain, */*",
        "Accept-Language": "en-GB,en;q=0.9,zh-CN;q=0.8,zh;q=0.7",
        "Content-Type": "application/json",
        "Origin": "https://ec.minmetals.com.cn",
        "Referer": "https://ec.minmetals.com.cn/open/home/purchase-info?tabIndex=2",
        "Sec-Fetch-Dest": "empty",
        "Sec-Fetch-Mode": "cors",
        "Sec-Fetch-Site": "same-origin",
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36",
        "^sec-ch-ua": "^\\^Not/A)Brand^^;v=^\\^8^^, ^\\^Chromium^^;v=^\\^126^^, ^\\^Google",
        "sec-ch-ua-mobile": "?0",
        "^sec-ch-ua-platform": "^\\^Windows^^^"
    }

    response = requests.post("https://ec.minmetals.com.cn/open/homepage/zbs/by-lx-page", headers=headers, cookies=cookies, json=data)
    print(response.text)



if __name__ == '__main__':
    index()
